﻿using System;
using System.Configuration;
using System.Xml;
using System.Collections.Specialized;

namespace Configuration
{
    class Common
    {
        /// <summary>
        /// 刷新app.config节点
        /// </summary>
        /// <param name="configName"></param>
        /// <param name="value"></param>
        public static void refreshConfig(String configName,String value)
        {
            XmlDocument doc = new XmlDocument();
            String fileName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

            doc.Load(fileName);

            XmlNodeList nodes = doc.GetElementsByTagName("add");

            for (int i = 0; i < nodes.Count; i++)
            {
                XmlAttribute att = nodes[i].Attributes["key"];
                if (att.Value == configName)
                {
                    att = nodes[i].Attributes["value"];
                    att.Value = value;
                    break;
                }
            }
            doc.Save(fileName);
            ConfigurationManager.RefreshSection("appSettings");

        }

        public static void getConfig(String sectionName)
        {
            NameValueCollection configValue = (NameValueCollection)ConfigurationManager.GetSection(sectionName);
        }


            
    }
}
